﻿using System;
using System.Collections.Generic;
using System.Linq;
using CCWP7.Model;
using System.Windows;
using Caliburn.Micro;

namespace CCWP7.CaliburnMicro
{
    public class RefreshServer : IResult
    {
        readonly IServerDataManager _serverDataManager;
        public RefreshServer(IServerDataManager serverDataManager)
        {
            _serverDataManager = serverDataManager;
        }

        public Server Server { get; set; }

        public void Execute(ActionExecutionContext context)
        {
            try
            {
                _serverDataManager.ReadAndUpdateServer(Server, s => Completed(this, new ResultCompletionEventArgs()));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Server.Name, MessageBoxButton.OK);
            }
        }

        public event EventHandler<ResultCompletionEventArgs> Completed = delegate
        {
        };
    }
}
